{{csrf_field()}}
<input type="hidden" id="goods_id" name="goods_id" value="{{$info->id?? 0}}">
<div class="layui-tab" lay-filter="demo" style="padding-bottom: 60px">
    <ul class="layui-tab-title">
        <li class="layui-this">基本信息</li>
        <li>商品图片</li>
        <li class="open_attr">规格属性</li>
        <li  class="open_attr">商品参数</li>
        <li>SEO</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <div class="layui-form-item">
                <label class="layui-form-label">商品名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name"  value="{{$info->name?? ''}}" lay-verify="required"  lay-reqText="商品名称必填" placeholder="请输入参数名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">别名</label>
                <div class="layui-input-block">
                    <input type="text" id="slug" name="slug" value="{{$info->slug?? old('slug')}}" autocomplete="off" placeholder="" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">根据标题自动生成 拼音或者英文单词 用‘-’连接 用于URL中</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">* 所属分类</label>
                <div class="layui-input-block">

                    <select lay-verify="required" lay-reqText="请选择分类" name="category_id" xm-select-direction="down" xm-select="category_id" xm-select-search-type="dl" xm-select-search>
                        @if(isset($init['category']))
                            @foreach($init['category'] as $key =>$val)
                                <option value="{{$val['id']}}" @if(isset($checkArr) && in_array($val['id'],$checkArr)) selected @endif>{{$val['cat_name']}}</option>
                            @endforeach
                        @endif
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">商品类型：</label>
                <div class="layui-input-block">

                    <select  name="goods_type_id" data-value="{{$info->goods_type_id?? 0}}" id="goods_type_id" xm-select-direction="down" xm-select="goods_type_id" xm-select-search-type="dl" xm-select-search xm-select-radio="">
                        @if(isset($init['goods_type']))
                            @foreach($init['goods_type'] as $key =>$val)
                                <option value="{{$val['id']}}" @if(isset($info->goods_type_id) && $info->goods_type_id == $val['id']) selected @endif>{{$val['name']}}</option>
                            @endforeach
                        @endif
                    </select>
                    <div class="layui-form-mid layui-word-aux">此处必选，关联规格属性、参数</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品品牌</label>
                <div class="layui-input-block">
                    <select  name="brand_id" xm-select-direction="down" xm-select="brand_id" xm-select-search-type="dl" xm-select-search xm-select-radio="">
                        @if(isset($init['brand']))
                            @foreach($init['brand'] as $key =>$val)
                                <option value="{{$val['id']}}" @if(isset($info->brand_id) && $val['id']== $info->brand_id)) selected @endif>{{$val['name']}}</option>
                            @endforeach
                        @endif
                    </select>

                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">商品编号：</label>
                <div class="layui-input-block">
                    <input type="text" name="bn"   value="{{$info->bn?? ''}}"  placeholder="请输入参数名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品简介：</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入商品简介" name="summary"  class="layui-textarea">{{$info->summary?? old('summary')}}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">重量：</label>
                <div class="layui-input-block">
                    <input type="text" name="weight"  value="{{$info->weight?? old('weight')}}"  placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">单位：</label>
                <div class="layui-input-block">
                    <input type="text" name="unit"  value="{{$info->unit?? old('unit')}}"  placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>



            <div class="layui-form-item">
                <label class="layui-form-label">上架：</label>
                <div class="layui-input-block">
                    <input type="checkbox" value="1" @if(isset($info->marketable) && $info->marketable) checked="" @endif name="marketable" lay-skin="switch" lay-filter="switchTest" lay-text="上架|下架">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">推荐：</label>
                <div class="layui-input-block">
                    <input type="checkbox" value="1" @if(isset($info->is_recommend) && $info->is_recommend) checked="" @endif name="is_recommend" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">热门：</label>
                <div class="layui-input-block">
                    <input type="checkbox" value="1" @if(isset($info->is_hot) && $info->is_hot) checked="" @endif name="is_hot" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">详情内容</label>
                <div class="layui-input-block">
                    <textarea id="post_content"  name="content">{{$info->content ?? old('content')}}</textarea>
                </div>
            </div>






        </div>
        <div class="layui-tab-item">
            <div class="layui-form-item">

                <div class="layui-input-block">

                    <div class="img_preview" id="img_preview">


                        @if(isset($info->manyImages) && !empty($info->manyImages))
                            @foreach($info->manyImages as $key=>$val)
                                <div class="imgdiv">
                                    <img src="{{$val->url}}"  class="layui-upload-img" style="width: 100px;height:100px;">
                                    <div id="operate">
                                        <div><a class="del" onclick="">删除</a>|<a class="setmain" onclick="">设为主图</a></div>
                                    </div>
                                    <input type='hidden' name='images[]' value="{{$val->id}}">
                                </div>
                            @endforeach
                        @endif
                        <div class="imgdiv goods-images-add upload-image">
                            <i class="layui-icon layui-icon-add-1"></i>
                            <div id="operate">
                                <div>&nbsp;</div>
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-mid layui-word-aux">预览图：[第一张图片为默认图，可拖动图片进行排序]</div>

                </div>
            </div>
        </div>
        <div class="layui-tab-item" id="view_many_attributes" data-spec="{{isset($info->spec_num)?$info->spec_num:0}}" data-value="{{isset($info->attributes_text)?json_encode($info->attributes_text):''}}" ></div>
        <div class="layui-tab-item" id="view_many_params" data-value="{{isset($info->params_text)?json_encode($info->params_text):''}}" ></div>
        <div class="layui-tab-item">内容5
            <div class="layui-form-item">
                <label class="layui-form-label">SEO 标题</label>
                <div class="layui-input-block">
                    <input type="text" name="meta_title" value="{{$info->meta_title??  old('meta_title')}}"  autocomplete="off" placeholder="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">SEO 关键字</label>
                <div class="layui-input-block">
                    <input type="text" name="meta_keywords" value="{{$info->meta_keywords?? old('meta_keywords')}}" autocomplete="off" placeholder="" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">SEO 描述</label>
                <div class="layui-input-block">
                    <textarea name="meta_description" placeholder="请输入内容" class="layui-textarea">{{$info->meta_description??''}}</textarea>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="layui-footer">
    <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>

{{--参数--}}
<script id="many_params" type="text/html">
    <h1>@{{d.name}}   @{{d.sky}}   @{{d.p}}</h1>
    @{{#  layui.each(d.many_params, function(index, item){ }}

    @{{#  if(item.type == 'text'){ }}
    <div class="layui-form-item">
        <label class="layui-form-label">@{{ item.name }}</label>
        <div class="layui-input-block">
            <input type="text" name="params[@{{ item.name }}]" value="@{{ empty(d.params) ? ' ': d.params[item.name] }}"  autocomplete="off" placeholder="" class="layui-input">
        </div>
    </div>
    @{{#  } else if(item.type == 'checkbox'){ }}

    <div class="layui-form-item">
        <label class="layui-form-label">@{{ item.name }}</label>
        <div class="layui-input-block">
            @{{#  layui.each(item.value_text, function(key, val){ }}
            <input type="checkbox" name="params[@{{ item.name }}][@{{val}}]" lay-skin="primary" title="@{{val}}"  @{{#  if( in_array(val,d.params[item.name])  && isset(d.params) ){ }} checked @{{#  } }}   >
            @{{#  }); }}
        </div>
    </div>
    @{{#  } else if(item.type == 'radio'){ }}
    <div class="layui-form-item">
        <label class="layui-form-label">@{{ item.name }}</label>
        <div class="layui-input-block">
            @{{#  layui.each(item.value_text, function(key, val){ }}
            <input type="radio" name="params[@{{ item.name }}]"  value="@{{val}}" title="@{{val}}" @{{#  if( val == d.params[item.name] && isset(d.params) ){ }} checked @{{#  } }} >
            @{{#  }); }}
        </div>
    </div>
    @{{#  } }}
    @{{#  }); }}
    </ul>
</script>
{{--属性--}}
<script id="many_attributes" type="text/html">

    <div class="layui-form-item">
        <label class="layui-form-label">商品规格</label>
        <div class="layui-input-block">
            <input type="radio" class="open_attributes" name="open_attributes" lay-filter="open_attributes" value="0" title="单规格" checked="">
            <input type="radio" id="open_attributes2" name="open_attributes"  lay-filter="open_attributes" value="1" title="多规格">
        </div>
    </div>

    <div class="attributes-box single-box">

        @if(isset($info->goodsItems))

        <div class="layui-form-item">
            <label class="layui-form-label">销售价：</label>
            <div class="layui-input-block">
                <input type="text" name="price"   value="{{$info->goodsItems[0]->price?? ''}}"  placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">成本价：</label>
            <div class="layui-input-block">
                <input type="text" name="costprice"  value="{{$info->goodsItems[0]->costprice?? ''}}"  placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">市场价：</label>
            <div class="layui-input-block">
                <input type="text" name="market_price"  value="{{$info->goodsItems[0]->market_price?? ''}}"  placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">货号：</label>
            <div class="layui-input-block">
                <input type="text" name="sn"  value="{{$info->goodsItems[0]->sn?? ''}}"  placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">库存：</label>
            <div class="layui-input-block">
                <input type="text" name="stock"  value="{{$info->goodsItems[0]->stock?? ''}}"  placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        @endif
    </div>
    <div class="attributes-box many-box">

        @{{#  layui.each(d.many_attributes, function(index, item){ }}
        <div class="layui-form-item">
            <label class="layui-form-label">@{{ item.name }}：</label>
            <div class="layui-input-block">
                @{{#  layui.each(item.list_value, function(key, val){ }}
                <input type="checkbox" name="attributes[@{{ item.name }}][]" value="@{{val.value}}" lay-skin="primary" title="@{{val.value}}" @{{#  if( in_array(val.value,d.attributes[item.name])  && isset(d.attributes) ){ }} checked @{{#  } }}>
                @{{#  }); }}
            </div>
        </div>
        @{{#  }); }}

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <a class="layui-btn layui-btn-sm generate-spec">生成规格</a>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block" id="view_generate_spec_table">

            </div>
        </div>



    </div>

</script>
{{--生成规格--}}
<script id="generate_spec_table" type="text/html">
    <table class="layui-table" lay-size="sm">
        <colgroup>
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>默认货品</th>
            <th>图片</th>
            <th>货号</th>
            <th>规格</th>
            <th>库存</th>
            <th><i class="required-color">*</i>销售价</th>
            <th>成本价</th>
            <th>市场价</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @{{#  layui.each(d.data, function(index, item){ }}
        <tr>
            <td>
                <input type="checkbox" name="item[@{{ item.spec_name }}][is_defalut]" value="1" lay-skin="switch" lay-text="是|否" {{--checked=""--}}>
            </td>
            <td class="spec-td">
                <a class="upSpecImage" href="javascript:;">选择图片</a>
                <div class="spec_image" style="display: none;">
                    <div class="spec_image_item">
                        <div class="del-img">
                            x
                        </div>
                        <img src="https://b2c.jihainet.com/static/images/default.png" id="image-1" style="width:60px;height:60px">
                    </div>
                    <input type="hidden" name="item[@{{ item.spec_name }}][image_id]" value="@{{ item.image_id }}">
                </div>
            </td>
            <td>
                <input type="text" name="item[@{{ item.spec_name }}][sn]" value="@{{ item.sn }}" placeholder="货号" autocomplete="off" class="layui-input">
            </td>
            <td>
                @{{ item.spec_name }}          </td>
            <td class="have-add-td">
                <input type="text" name="item[@{{ item.spec_name }}][stock]" value="0" placeholder="库存" autocomplete="off" class="layui-input goods-stock">
                <input type="checkbox" name="item[@{{ item.spec_name }}][stock_type]" lay-skin="switch" lay-text="增加|减少" checked=""><div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>增加</em><i></i></div>
                <a href="javascript:;" class="help-tip" data-tip="总库存：0，冻结库存：0"><i class="iconfont icon-wenhao"></i></a>

            </td>
            <td>
                <input type="text" name="item[@{{ item.spec_name }}][price]" value="@{{ item.price }}" placeholder="销售价" autocomplete="off" class="layui-input">
            </td>
            <td>
                <input type="text" name="item[@{{ item.spec_name }}][costprice]" value="@{{ item.costprice }}" placeholder="成本价" autocomplete="off" class="layui-input">
            </td>
            <td>
                <input type="text" name="item[@{{ item.spec_name }}][market_price]" value="@{{ item.market_price }}" placeholder="市场价" autocomplete="off" class="layui-input">
            </td>
            <td>
                <a class="layui-btn layui-btn-danger layui-btn-xs del-class">删除</a>
            </td>
        </tr>
        @{{#  }); }}
        </tbody>
    </table>
</script>
{{--图片--}}
<script id="goods_images" type="text/html">
    @{{#  layui.each(d, function(index, item){ }}
    <div class="imgdiv">
        <img src="@{{ item.src }}"  class="layui-upload-img" style="width: 100px;height:100px;">
        <div id="operate">
            <div><a class="del" onclick="">删除</a>|<a class="setmain" onclick="">设为主图</a></div>
        </div>
        <input type='hidden' name='images[]' value="@{{ item.image_id }}">
    </div>
    @{{#  }); }}
</script>
<textarea id="edit_image" style="display: none;"></textarea>
@section('script')
    <style>
        #img_preview{
            display: inline;
            float: left;
            margin-top: 20px;
            overflow: hidden;
        }
        .imgdiv {
            display: inline-block;
            float: left;
            text-align: center;
            border: 1px solid #ccc;
            padding: 5px;
            padding-bottom: 0;
            margin: 0 10px 10px 0;
        }
        #operate{
            margin-top: 5px;
        }
        #operate a{
            cursor:pointer
        }
        #operate a:hover{
            color: #009688;
        }
        .attributes-box{ display: none}
        .single-box{ display: block}
        .spec_image_item {
            position: relative;
            display: inline-block;
        }
        .del-img {
            position: absolute;
            background-color: rgba(0,0,0,.5);
            color: #fff;
            width: 13px;
            height: 13px;
            line-height: 12px;
            font-size: 10px;
            display: inline-block;
            text-align: center;
            border-radius: 50%;
            right: -6px;
            top: -6px;
        }
        .goods-images-add{}
        .goods-images-add i{ font-size: 36px; width: 100px; display: block; text-align: center; height: 100px; line-height:130px}
    </style>
    <script src="{{ asset('static/admin/js/jquery.min.js') }}"></script>
    <link rel="stylesheet" href="{{ asset('static/admin/css/formSelects-v4.css') }}">
    <link rel="stylesheet" href="{{ asset('static/admin/css/inputTags.css') }}">
    <script src="{{ asset('static/admin/js/ddsort/ddsort.js') }}"></script>
    <script type="text/javascript">
        var ue = UE.getEditor('post_content');
    </script>
    <script>
        layui.use(['layer', 'form','jquery','formSelects','strpy','inputTags','element','laytpl'], function(){
            var layer = layui.layer,
                form =layui.form,
                element=layui.form,
                laytpl = layui.laytpl,
                inputTags = layui.inputTags,
                $  = layui.jquery;

            if($('#goods_type_id').data('value') > 0)
            {
                getAttr($('#goods_type_id').data('value'));

                console.log($('#goods_type_id').data('value'));

                console.log($('#many_params').html());
            }

            var _editor = UE.getEditor("edit_image",{
                initialFrameWidth:800,
                initialFrameHeight:300,
                zIndex:19891026,
            });
            _editor.ready(function (){
                _editor.hide();
                _editor.addListener('beforeInsertImage',function(t,arg){
                    console.log(arg);
                    console.log(t);
                    var obj = _editor.queryCommandValue("serverparam");
                    if(obj.type == "upload-image"){
                        if(arg.length>5){
                            layer.msg("最多只能选择5张图片，请重新选择");
                            return false;
                        }
                        if(arg.length>0) {
                            var getTpl = goods_images.innerHTML;
                            laytpl(getTpl).render(arg, function(html){
                                $('.goods-images-add').before(html);
                            });
                        }else{
                            layer.msg("请先选择图片");
                            return false;
                        }
                    }else if(obj.type == "spec"){
                        if(arg.length>1){
                            layer.msg("最多只能选择1张图片，请重新选择");
                            return false;
                        }
                        if(arg.length>0) {
                            var specImageTd = obj.specItem.parent().find(".spec_image");
                            specImageTd.find('img').attr('src',arg[0].src);
                            specImageTd.find('input').val(arg[0].image_id);
                            specImageTd.show();
                        }else{
                            layer.msg("请先选择图片");
                            return false;
                        }
                    }
                    return true;
                });
            });

            $("body").on("click", ".upload-image", function () {

                //此处进行初始化
                var obj = _editor.queryCommandValue("serverparam");
                obj.type = "upload-image";
                obj.uploadImageItem = $(this);
                var uploadImage = _editor.getDialog("insertimage");
                console.log(obj);
                uploadImage.open();
            });

            $("#name, #slug").change(function(){
                var strpy= layui.strpy($(this).val(),'-');
                $('#slug').val(strpy.replace(/\ /g, "-"));
            });

            //监听提交
            form.on('submit(post-submit)', function(data){
                var tagName=[];
                $('#tags em').each(function(i){
                    tagName.push($(this).text());
                });
                $('#post_tag').val(tagName.join(','));
                //layer.msg(JSON.stringify(data.field));
                //console.log(JSON.stringify(data.field));
                // return false;
            });
            //商品图片排序
            $('.img_preview').DDSort({
                target: '.imgdiv',
                delay: 100,
                floatStyle: {
                    'border': '1px solid #ccc',
                    'background-color': '#fff'
                }
            });
            //监听radio单选
            form.on('radio(open_attributes)', function(data){

                var formSelects = layui.formSelects;

                console.log(formSelects.value('goods_type_id','valStr')); //得到radio原始DOM对象

                console.log(data.elem); //得到radio原始DOM对象
                console.log(data.value); //被点击的radio的value值
                $('.attributes-box').hide();
                if(data.value ==1)
                {
                    $('.many-box').show();
                }
                else{
                    $('.single-box').show();
                }

            });
            //删除相册图
            $("body").on("click", ".del", function () {
                $(this).parents(".imgdiv").remove();
            });
            //设为主图
            $("body").on("click", ".setmain", function () {
                console.log($(this).parents(".imgdiv").html());
                $(this).parents(".imgdiv").remove();
                var imgDiv = '<div class="imgdiv">'+$(this).parents(".imgdiv").html()+'</div>';
                $("#img_preview").prepend(imgDiv);
            });

            element.on('tab(goods)', function(data){
                console.log(this); //当前Tab标题所在的原始DOM元素
                console.log(data.index); //得到当前Tab的所在下标
                console.log(data.elem); //得到当前的Tab大容器
            });
            function getAttr(id) {
                $.getJSON("{{route('admin.goods.type.item')}}",{goods_type_id:id},function (e) {
                    console.log(e);
                    console.log(e.data);
                    console.log(e.data.many_params);

                    //编辑选中的参数
                    var hasParams=$('#view_many_params').data("value");
                    e.data.params = [];
                    if(!empty(hasParams))
                    {
                        e.data.params=hasParams;
                    }

                    //编辑选中的属性规格
                    var hasAttributes=$('#view_many_attributes').data("value");
                    e.data.attributes = [];
                    if(!empty(hasAttributes))
                    {
                        e.data.attributes=hasAttributes;
                    }

                    e.data.sky='sky8652';
                    e.data.p='sky8652';


                    console.log(e.data.params);

                    if(e.data.many_params)
                    {
                        //todo
                        var getTpl=$('#many_params').html()
                            // var getTpl = many_params.innerHTML
                            ,view = document.getElementById('view_many_params');
                        laytpl(getTpl).render(e.data, function(html){
                            view.innerHTML = html;
                        });
                    }

                    if(e.data.many_attributes)
                    {
                        //todo
                        var getTpl = many_attributes.innerHTML
                            ,view = document.getElementById('view_many_attributes');
                        laytpl(getTpl).render(e.data, function(html){
                            view.innerHTML = html;
                        });
                    }
                    form.render();


                    //模拟点击radio
                    var input =$('input:radio[name="open_attributes"]')[1];
                    $(input).next().click();
                    $('.generate-spec').click();
                    console.log(99)

                    if($('#view_many_attributes').data('spec') >1)
                    {

                    }


                })

            }
            //生成规格
            $("body").on("click",".generate-spec",function(){
                var list = $('#view_many_attributes input[type=checkbox]:checked');
                console.log(list);
                if(list.length>0){
                    var data = $('#view_many_attributes input[type=checkbox]:checked').serialize();

                    var data = $('#goods_id,#view_many_attributes input[type=checkbox]:checked,#view_many_attributes input[type=radio]:checked').serialize();
                    // var data =$('.layui-form').serialize();
                    console.log(data);
                    // return false;

                    $.ajax({
                        url: "{{route('admin.goods.splice')}}",
                        type: 'get',
                        data: data,
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        dataType: 'json',
                        success: function (e) {

                            if (e.code == 0) {
                                if(e)
                                {
                                    //todo
                                    var getTpl = generate_spec_table.innerHTML
                                        ,view = document.getElementById('view_generate_spec_table');
                                    laytpl(getTpl).render(e, function(html){
                                        view.innerHTML = html;
                                    });
                                }
                                form.render();
                            } else {
                                layer.msg(e.msg);
                            }
                        }
                    });

                }else{
                    layer.msg("请选择属性");
                    return false;
                }
                return false;
            });
            //删除行规格
            $("body").on("click", ".del-class", function () {
                var _this=$(this);
                $('#view_generate_spec_table tr ').removeClass("trremove");
                _this.parents('tr').addClass("trremove");
                layer.confirm('确认'+$(this).text()+'吗？',{icon: 3, title:'提示'}, function(index){
                    _this.parents('tr').remove();
                    layer.close(index);
                },function () {
                    _this.parents('tr').removeClass("trremove");
                })
            });

            //上传规格图片
            $("body").on("click", ".upSpecImage", function () {
                var obj = _editor.queryCommandValue("serverparam");
                obj.type = "spec";
                obj.specItem = $(this);
                var specImage = _editor.getDialog("insertimage");

                console.log(obj);
                specImage.open();
            });
            // 删除规格图片
            $("body").on("click", ".del-img", function () {
                var specImageDiv =  $(this).parent().parent();
                specImageDiv.find('img').attr('src','');
                specImageDiv.find('input').val('');
                specImageDiv.hide();
            })

            //商品类型
            layui.formSelects.on('goods_type_id', function(id, vals, val, isAdd, isDisabled){
                //id:           点击select的id
                //vals:         当前select已选中的值
                //val:          当前select点击的值
                //isAdd:        当前操作选中or取消
                //isDisabled:   当前选项是否是disabled
                //alert(1);
                layer.confirm('更换类型后，产品需重新生成，确定要更换吗？',{icon: 3, title:'提示'}, function(index){
                    var id =val.value;
                    if(id > 0)
                    {
                        getAttr(id);
                    }
                    layer.close(index);
                })

                console.log(val.value);
                //如果return false, 那么将取消本次操作
                // return false;
            });







        });
    </script>

@endsection